<!DOCTYPE HTML>


	
                
<?php 
//require_once '../funciones.php'; 
function  conexion(){
	global $conexion;
	$conexion = mysql_connect("localhost","root","290583");
	mysql_select_db("seg",$conexion) OR die ("error". mysql_errno());
	mysql_query("SET NAMES 'utf8'");
	if(!$conexion)
	{
		echo "Error en la conexion";
	}
}

conexion();
$mov='A-LKK317';

        $result=mysql_query("SHOW FIELDS FROM seg.eventos");
         while($row=mysql_fetch_array($result)){
            $txt=$txt. $row['Field'].",";
         }
         $txt= substr($txt, 0, -1)."\r\n";


   $result=mysql_query("select e.movil as mo, e.fechaevento as fec, e.latitud as lat , e.longitud as lon, 
e.ubicacion as ub,e.descripcion as des, e.`Velocidad` as vel, e.`Observaciones` as ob
from seg.eventos as e
where e.movil like 'A-LKK317' and month(e.fechaevento)= 3 ");
   
  
              
		
                while($row=mysql_fetch_array($result)){
                     
                        $txt= $txt."".$row['mo'].",".$row['fec'].", ".$row['lat'].", ".$row['lon'].", ".str_replace(",", "", $row['ub']).","
                            .$row['des'].", ".$row['vel'].",".str_replace(",", "", $row['ob'])."\r\n";
                    $i++;
                         
                
                   
                }   
                 
              
                  $outputDir = '.';
                 saveFile($txt, $outputDir,$mov,"txt");
function saveFile(&$texto, $outputDir = '.', $mov, $ext)
    {
        if (!$texto) return false;
 
        try
        {
           
            $handle = fopen($outputDir."/$mov-".date("Ymd-His", time()).".$ext",'w+');
            
            $lin = "/$mov-".date("Ymd-His", time()).".$ext";
            echo  '<A href="/seg/kml/'.$lin.'">Descargar '.$lin.'</A>';
            fwrite($handle, $texto);
            fclose($handle);
        }
        catch (Exception $e)
        {
            var_dump($e->getMessage());
            return false;
        }
 
        return true;
    }       
                 
                 
                 ?> 



